package cn.gzmli.dtt.common.workflow.service;

import cn.gzmli.dtt.common.entity.PageInfo;
import cn.gzmli.dtt.common.utils.BaseService;
import cn.gzmli.dtt.common.workflow.dao.FlowNodeMessageDao;
import cn.gzmli.dtt.common.workflow.entity.FlowNodeMessage;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by xsx on 2018/1/7.
 */
@Service
@Transactional
public class FlowNodeMessageService extends BaseService<FlowNodeMessage> {

    @Autowired
    FlowNodeMessageDao flowNodeMessageDao;

    @Override
    public List<FlowNodeMessage> getByCondition(DetachedCriteria condition, PageInfo pageInfo) throws Exception {
        if (pageInfo.getPageSize() > 0){
            return this.flowNodeMessageDao.queryEntityByPage(condition, pageInfo);
        }else{
            return this.flowNodeMessageDao.queryEntity(condition);
        }
    }

    public void updateStatus(Integer id, Integer status) throws Exception {
        final String sql = "UPDATE flownode_message SET status=? WHERE id=?";
        this.getDao().getJdbcTemplate().update(sql, status, id);
    }
}
